#include "snapshotlistmodel.h"

 int SnapshotListModel::rowCount(const QModelIndex &parent) const
 {
     return snapshotList.count();
 }

 QVariant SnapshotListModel::data(const QModelIndex &index, int role) const
 {
     if (!index.isValid())
         return QVariant();

     if (index.row() >= snapshotList.size())
         return QVariant();

     if (role == Qt::DisplayRole)
         return snapshotList.at(index.row())->name();
     else
         return QVariant();
 }

 QVariant SnapshotListModel::headerData(int section, Qt::Orientation orientation,
                                      int role) const
 {
     
         return QVariant();

 }
/*
QModelIndex  SnapshotListModel::index(int row, int column, const QModelIndex & parent) 
{
  return createIndex (row, column);
}
*/
bool SnapshotListModel::addSnapshot(Snapshot *new_s)
{
foreach(Snapshot *s, snapshotList){
  if(s->name()==new_s->name())
    return false;
}
beginInsertRows(QModelIndex(), snapshotList.size()-1, snapshotList.size()-1);
  snapshotList.append(new_s);
 endInsertRows();
}

void SnapshotListModel::removeSnapshot(const QModelIndex &index)
{
int pos=index.row();
 beginRemoveRows(QModelIndex(), pos, pos);
  snapshotList.removeAt(pos);
 endRemoveRows();
}
